package com.java.control.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;

import com.java.control.AbstractAdminCommandController;
import com.java.control.search.SearchStat;
import com.java.control.search.UserSearchCond;
import com.java.entity.Department;
//import com.java.entity.Role;
import com.java.entity.User;
import com.java.mis.UserType;
import com.java.service.DeptService;
import com.java.service.RoleService;
import com.java.service.UserService;

/**
 * 人员管理
 * @author wqf
 * @version  Nov 24, 2011 12:00:53 PM
 */
public class UserListController extends AbstractAdminCommandController {

	public UserListController(){
		this.setCommandClass(UserSearchCond.class);
	}	

	protected ModelAndView executeRequest(HttpServletRequest request,HttpServletResponse response,Object command)
		throws Exception{
		
		UserSearchCond searchCond = (UserSearchCond)command;
		
		ModelAndView mav=new ModelAndView(this.view);
		searchCond.setPageSize(10L);
		SearchStat searchStat=this.userService.getSearchStat(User.class, searchCond);
		List<User> peopleList=this.userService.search(User.class,searchCond);
		mav.addObject("searchStat", searchStat);
		mav.addObject("searchCond", searchCond);
		mav.addObject("userList", peopleList);		
		
		//部门信息
		List<Department> deptList = this.deptService.search(Department.class);
		mav.addObject("deptList", deptList);
		
		//角色信息
//		List<Role> roleList = this.roleService.search(Role.class);
//		mav.addObject("roleList", roleList);
		mav.addObject("userType", UserType.values());
		return mav;
		
	}
		
	private String view;
	private UserService userService;
	private DeptService deptService;
	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	private RoleService roleService;
	
	public void setDeptService(DeptService deptService) {
		this.deptService = deptService;
	}

	public void setView(String view) {
		this.view = view;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
}
